/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cda.memo;

import android.util.Log;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author Shyzkanza
 */
public class GestionFichier {

    public GestionFichier() {
    
    }
    
    public void verifFichier() throws IOException{
        boolean repDejaExistant = false;
        File sdcard = new File("/sdcard");
        String[] contenuSdCard = sdcard.list();
        int i=0;
        while(i<contenuSdCard.length && !repDejaExistant){
            if(contenuSdCard[i].compareTo("cda.memo")==0){
                repDejaExistant = true;
            }
            i++;
        }
        File rep = new File("/sdcard/cda.memo/");
        if(!repDejaExistant){
            rep.mkdirs();
        }
        
        sdcard = new File("/sdcard/cda.memo");
        contenuSdCard = sdcard.list();
        i=0;
        while(i<contenuSdCard.length && !repDejaExistant){
            if(contenuSdCard[i].compareTo("Categorie.xml")==0){
                repDejaExistant = true;
            }
            i++;
        }
        if(!repDejaExistant){
            sdcard = new File("/sdcard/cda.memo/Categorie.xml");
            BufferedWriter bf = new BufferedWriter(new FileWriter(sdcard));
            bf.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<categories>\n</categories>");
            bf.flush();
            bf.close();
        }
        
        contenuSdCard = sdcard.list();
        i=0;
        while(i<contenuSdCard.length && !repDejaExistant){
            if(contenuSdCard[i].compareTo("Fidelite.xml")==0){
                repDejaExistant = true;
            }
            i++;
        }
        if(!repDejaExistant){
            sdcard = new File("/sdcard/cda.memo/Fidelite.xml");
            BufferedWriter bf = new BufferedWriter(new FileWriter(sdcard));
            bf.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<fidelites>\n</fidelites>");
            bf.flush();
            bf.close();
        }
    }
}
